package pay;

/**
 * 简单工程 + 策略模式.
 *
 * @author GongXincheng
 * @since 2019-09-14 14:04
 */
public class YouHuiContext {

    private Strategy strategy;

    public YouHuiContext(YouHuiEnum youHuiEnum) {
        switch (youHuiEnum) {
            case YUAN_JIA:
                strategy = new StraregyYuanJia();
                break;
            case DAZHE_6:
                strategy = new StraregyDaZhe(0.6);
                break;
            case DAZHE_9:
                strategy = new StraregyDaZhe(0.9);
                break;
            case MANJIAN_300_20:
                strategy = new StraregyManJian(300, 20);
                break;
            case MANJIAN_700_50:
                strategy = new StraregyManJian(700, 50);
                break;
            default:
                throw new RuntimeException("无该优惠类型");
        }
    }

    /**
     * 获取最终价格.
     */
    public double getResultPrice(double totalPrice) {
        return strategy.getResultPrice(totalPrice);
    }

}
